/*
 * @Author: szx
 * @Date: 2022-04-05 14:04:37
 * @LastEditTime: 2022-04-06 12:29:52
 * @Description:
 * @FilePath: \leetcode\剑指offerII\037\037.js
 */
/**
 * @param {number[]} asteroids
 * @return {number[]}
 */
var asteroidCollision = function (asteroids) {
    const st = [];
    for (let i of asteroids) {
        while (st.length && i < 0 && st[st.length - 1] > 0) {
            if (0 < i + st[st.length - 1]) {
                i = 0;
            } else if (0 == i + st[st.length - 1]) {
                i = 0;
                st.pop();
            } else st.pop();
        }
        if (i != 0) st.push(i);
    }
    return st;
};
console.log(asteroidCollision([5, 10, -5]));
console.log(asteroidCollision([8, -8]));
console.log(asteroidCollision([10, 2, -5]));
console.log(asteroidCollision([-2, -1, 1, 2]));
